// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import './utils/polyfill'
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/'
import './element-ui'
import Layout from './components/layout'
import NoDataTips from '@/components/nodata'
import titleMixin from './utils/titleMixin'
import permission from '@/utils/permission'
import Cookie from '@/utils/cookie'
import {
  parseTime,
  moneyFormat,
  dateDiff
} from './utils/assist'
import loading from './directive/loading'

window.$(() => {
  // Vue.config.productionTip = false

  // 布局组件
  Vue.component('layout', Layout)
  Vue.component('NoDataTips', NoDataTips)
  // 全局混合，document.title
  Vue.mixin(titleMixin, permission)
  // 全局混合权限
  Vue.mixin(permission)

  Vue.mixin({
    directives: {
      loading
    }
  })

  Vue.filter('parseTime', parseTime)
  Vue.filter('moneyFormat', moneyFormat)
  Vue.filter('dateDiff', dateDiff)

  Vue.prototype.JSONo = (t, b) => {
    return Object.assign({}, t, b)
  }

  (function () {
    let url
    if (/\.zhongyi9999\.com/.test(window.location.href)) {
      url = '//open.zhongyi9999.com/#'
    }
    if (/\.hxkjtest\.com/.test(window.location.href)) {
      url = '//open.hxkjtest.com/#'
    }
    if (/localhost/.test(window.location.href)) {
      url = '//localhost:8088/#'
    }
    Vue.prototype.UCurl = url

    let ref = document.referrer
    let host = location.host
    if (ref) {
      let reg = new RegExp(host)
      if (!reg.test(ref)) {
        Cookie.set('referrer', ref)
      }
    } else {
      Cookie.set('referrer', '')
    }
  })()

  window.$store = store
  /* eslint-disable no-new */
  new Vue({
    el: '#app',
    router,
    store,
    components: {
      App,
      NoDataTips
    },
    mounted () {
      // You'll need this for renderAfterDocumentEvent.
      document.dispatchEvent(new Event('render-event'))
    },
    template: '<App/>'
  })
})
